﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiMovMovieManagerForm
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using C1.Win.C1FlexGrid;
using DnProcessSimulateCommands.MovieRecorder;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Resources;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands;

public class CUiMovMovieManagerForm : TxForm
{
  private const int m_defaultCreationMovieOption = 0;
  private const string SETTINGS_REGISTRY_PARAMETER = "Movie Manager Settings";
  private CApMovMovieManagerApp m_movieManagerApp;
  private ToolBarButton m_markAllToolBarButton;
  private ToolBarButton m_markByLavelToolBarButton;
  private ToolBarButton m_makrLinesWithoutMoviesToolBarButton;
  private ToolBarButton m_clearAllMarksToolBarButton;
  private ToolBarButton m_separatorToolBarButton1;
  private ToolBarButton m_CreateMovieToolBarButton;
  private Button m_buttonCancel;
  private TxToolBar m_toolBarCommands;
  private ImageList m_imageListToolBarButtons;
  private SplitContainer m_splitContainerMain;
  private SplitContainer m_splitContainerPreview;
  private CUiMovProcessTreeGridWrapper m_processTreeFlexGrid;
  private GroupBox m_aviFilesGroupBox;
  private CUiMovAviFilesGridWrapper m_aviFilesFlexGrid;
  private Button m_buttonPreviewMovie;
  private Button m_removeButton;
  private Label m_cannotPlayLabel;
  private CUiMovMoviePlayerControl m_cUiMovieManagerControl;
  private ToolBarButton m_toolBarMovieSettings;
  private ToolBarButton m_separatorToolBarButton2;
  private IContainer components;
  private const int SC_CLOSE = 61536;
  private const int MF_DISABLE = 1;
  private const int MF_ENABLED = 0;

  public CUiMovMovieManagerForm()
  {
    this.InitializeComponent();
    this.m_movieManagerApp = new CApMovMovieManagerApp();
    this.RegisterToDocumentEvents();
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    this.components = (IContainer) new Container();
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiMovMovieManagerForm));
    this.m_splitContainerMain = new SplitContainer();
    this.m_splitContainerPreview = new SplitContainer();
    this.m_aviFilesGroupBox = new GroupBox();
    this.m_buttonPreviewMovie = new Button();
    this.m_removeButton = new Button();
    this.m_processTreeFlexGrid = new CUiMovProcessTreeGridWrapper();
    this.m_aviFilesFlexGrid = new CUiMovAviFilesGridWrapper();
    this.m_cannotPlayLabel = new Label();
    this.m_cUiMovieManagerControl = new CUiMovMoviePlayerControl();
    this.m_toolBarCommands = new TxToolBar();
    this.m_markAllToolBarButton = new ToolBarButton();
    this.m_markByLavelToolBarButton = new ToolBarButton();
    this.m_makrLinesWithoutMoviesToolBarButton = new ToolBarButton();
    this.m_clearAllMarksToolBarButton = new ToolBarButton();
    this.m_separatorToolBarButton1 = new ToolBarButton();
    this.m_toolBarMovieSettings = new ToolBarButton();
    this.m_separatorToolBarButton2 = new ToolBarButton();
    this.m_CreateMovieToolBarButton = new ToolBarButton();
    this.m_imageListToolBarButtons = new ImageList(this.components);
    this.m_buttonCancel = new Button();
    this.m_splitContainerMain.BeginInit();
    this.m_splitContainerMain.Panel1.SuspendLayout();
    this.m_splitContainerMain.Panel2.SuspendLayout();
    this.m_splitContainerMain.SuspendLayout();
    ((ISupportInitialize) this.m_processTreeFlexGrid).BeginInit();
    this.m_splitContainerPreview.BeginInit();
    this.m_splitContainerPreview.Panel1.SuspendLayout();
    this.m_splitContainerPreview.Panel2.SuspendLayout();
    this.m_splitContainerPreview.SuspendLayout();
    this.m_aviFilesGroupBox.SuspendLayout();
    ((ISupportInitialize) this.m_aviFilesFlexGrid).BeginInit();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this.m_splitContainerMain, "m_splitContainerMain");
    this.m_splitContainerMain.Name = "m_splitContainerMain";
    this.m_splitContainerMain.Panel1.Controls.Add((Control) this.m_processTreeFlexGrid);
    componentResourceManager.ApplyResources((object) this.m_splitContainerMain.Panel1, "m_splitContainerMain.Panel1");
    this.m_splitContainerMain.Panel2.Controls.Add((Control) this.m_splitContainerPreview);
    componentResourceManager.ApplyResources((object) this.m_splitContainerMain.Panel2, "m_splitContainerMain.Panel2");
    ((C1FlexGridBase) this.m_processTreeFlexGrid).AllowDragging = (AllowDraggingEnum) 3;
    componentResourceManager.ApplyResources((object) this.m_processTreeFlexGrid, "m_processTreeFlexGrid");
    ((C1FlexGridBase) this.m_processTreeFlexGrid).EmptyAsNull = false;
    ((C1FlexGridBase) this.m_processTreeFlexGrid).ExtendLastCol = true;
    ((C1FlexGridBase) this.m_processTreeFlexGrid).FocusRect = (FocusRectEnum) 0;
    ((Control) this.m_processTreeFlexGrid).Name = "m_processTreeFlexGrid";
    ((RowColCollection) ((C1FlexGridBase) this.m_processTreeFlexGrid).Rows).Count = 1;
    ((RowColCollection) ((C1FlexGridBase) this.m_processTreeFlexGrid).Rows).DefaultSize = 19;
    ((C1FlexGridBase) this.m_processTreeFlexGrid).SelectionMode = (SelectionModeEnum) 7;
    ((C1FlexGridBase) this.m_processTreeFlexGrid).StyleInfo = componentResourceManager.GetString("m_processTreeFlexGrid.StyleInfo");
    ((C1FlexGridBase) this.m_processTreeFlexGrid).Tree.Column = 0;
    ((C1FlexGridBase) this.m_processTreeFlexGrid).SelChange += new EventHandler(this.m_processTreeFlexGrid_SelChange);
    ((Control) this.m_processTreeFlexGrid).MouseDown += new MouseEventHandler(this.m_processTreeFlexGrid_MouseDown);
    componentResourceManager.ApplyResources((object) this.m_splitContainerPreview, "m_splitContainerPreview");
    this.m_splitContainerPreview.Name = "m_splitContainerPreview";
    this.m_splitContainerPreview.Panel1.Controls.Add((Control) this.m_aviFilesGroupBox);
    componentResourceManager.ApplyResources((object) this.m_splitContainerPreview.Panel1, "m_splitContainerPreview.Panel1");
    this.m_splitContainerPreview.Panel2.Controls.Add((Control) this.m_cannotPlayLabel);
    this.m_splitContainerPreview.Panel2.Controls.Add((Control) this.m_cUiMovieManagerControl);
    componentResourceManager.ApplyResources((object) this.m_splitContainerPreview.Panel2, "m_splitContainerPreview.Panel2");
    this.m_aviFilesGroupBox.Controls.Add((Control) this.m_buttonPreviewMovie);
    this.m_aviFilesGroupBox.Controls.Add((Control) this.m_removeButton);
    this.m_aviFilesGroupBox.Controls.Add((Control) this.m_aviFilesFlexGrid);
    componentResourceManager.ApplyResources((object) this.m_aviFilesGroupBox, "m_aviFilesGroupBox");
    this.m_aviFilesGroupBox.Name = "m_aviFilesGroupBox";
    this.m_aviFilesGroupBox.TabStop = false;
    componentResourceManager.ApplyResources((object) this.m_buttonPreviewMovie, "m_buttonPreviewMovie");
    this.m_buttonPreviewMovie.Name = "m_buttonPreviewMovie";
    this.m_buttonPreviewMovie.Click += new EventHandler(this.m_buttonPreviewMovie_Click);
    componentResourceManager.ApplyResources((object) this.m_removeButton, "m_removeButton");
    this.m_removeButton.Name = "m_removeButton";
    this.m_removeButton.Click += new EventHandler(this.m_removeButton_Click);
    ((C1FlexGridBase) this.m_aviFilesFlexGrid).AllowDragging = (AllowDraggingEnum) 3;
    componentResourceManager.ApplyResources((object) this.m_aviFilesFlexGrid, "m_aviFilesFlexGrid");
    ((C1FlexGridBase) this.m_aviFilesFlexGrid).EmptyAsNull = false;
    ((C1FlexGridBase) this.m_aviFilesFlexGrid).ExtendLastCol = true;
    ((C1FlexGridBase) this.m_aviFilesFlexGrid).FocusRect = (FocusRectEnum) 0;
    ((C1FlexGridBase) this.m_aviFilesFlexGrid).HighLight = (HighLightEnum) 2;
    ((Control) this.m_aviFilesFlexGrid).Name = "m_aviFilesFlexGrid";
    ((RowColCollection) ((C1FlexGridBase) this.m_aviFilesFlexGrid).Rows).Count = 1;
    ((RowColCollection) ((C1FlexGridBase) this.m_aviFilesFlexGrid).Rows).DefaultSize = 19;
    ((C1FlexGridBase) this.m_aviFilesFlexGrid).SelectionMode = (SelectionModeEnum) 7;
    ((C1FlexGridBase) this.m_aviFilesFlexGrid).StyleInfo = componentResourceManager.GetString("m_aviFilesFlexGrid.StyleInfo");
    ((C1FlexGridBase) this.m_aviFilesFlexGrid).BeforeSelChange += new RangeEventHandler(this.m_aviFilesFlexGrid_BeforeSelChange);
    ((C1FlexGridBase) this.m_aviFilesFlexGrid).SelChange += new EventHandler(this.m_aviFilesFlexGrid_SelChange);
    componentResourceManager.ApplyResources((object) this.m_cannotPlayLabel, "m_cannotPlayLabel");
    this.m_cannotPlayLabel.Name = "m_cannotPlayLabel";
    this.m_cUiMovieManagerControl.CausesValidation = false;
    componentResourceManager.ApplyResources((object) this.m_cUiMovieManagerControl, "m_cUiMovieManagerControl");
    this.m_cUiMovieManagerControl.Name = "m_cUiMovieManagerControl";
    componentResourceManager.ApplyResources((object) this.m_toolBarCommands, "m_toolBarCommands");
    ((ToolBar) this.m_toolBarCommands).Buttons.AddRange(new ToolBarButton[8]
    {
      this.m_markAllToolBarButton,
      this.m_markByLavelToolBarButton,
      this.m_makrLinesWithoutMoviesToolBarButton,
      this.m_clearAllMarksToolBarButton,
      this.m_separatorToolBarButton1,
      this.m_toolBarMovieSettings,
      this.m_separatorToolBarButton2,
      this.m_CreateMovieToolBarButton
    });
    ((ToolBar) this.m_toolBarCommands).Divider = false;
    ((ToolBar) this.m_toolBarCommands).ImageList = this.m_imageListToolBarButtons;
    ((Control) this.m_toolBarCommands).Name = "m_toolBarCommands";
    ((ToolBar) this.m_toolBarCommands).ButtonClick += new ToolBarButtonClickEventHandler(this.m_toolBarCommands_ButtonClick);
    componentResourceManager.ApplyResources((object) this.m_markAllToolBarButton, "m_markAllToolBarButton");
    this.m_markAllToolBarButton.Name = "m_markAllToolBarButton";
    componentResourceManager.ApplyResources((object) this.m_markByLavelToolBarButton, "m_markByLavelToolBarButton");
    this.m_markByLavelToolBarButton.Name = "m_markByLavelToolBarButton";
    this.m_markByLavelToolBarButton.Style = ToolBarButtonStyle.DropDownButton;
    componentResourceManager.ApplyResources((object) this.m_makrLinesWithoutMoviesToolBarButton, "m_makrLinesWithoutMoviesToolBarButton");
    this.m_makrLinesWithoutMoviesToolBarButton.Name = "m_makrLinesWithoutMoviesToolBarButton";
    componentResourceManager.ApplyResources((object) this.m_clearAllMarksToolBarButton, "m_clearAllMarksToolBarButton");
    this.m_clearAllMarksToolBarButton.Name = "m_clearAllMarksToolBarButton";
    this.m_separatorToolBarButton1.Name = "m_separatorToolBarButton1";
    this.m_separatorToolBarButton1.Style = ToolBarButtonStyle.Separator;
    componentResourceManager.ApplyResources((object) this.m_toolBarMovieSettings, "m_toolBarMovieSettings");
    this.m_toolBarMovieSettings.Name = "m_toolBarMovieSettings";
    this.m_separatorToolBarButton2.Name = "m_separatorToolBarButton2";
    this.m_separatorToolBarButton2.Style = ToolBarButtonStyle.Separator;
    componentResourceManager.ApplyResources((object) this.m_CreateMovieToolBarButton, "m_CreateMovieToolBarButton");
    this.m_CreateMovieToolBarButton.Name = "m_CreateMovieToolBarButton";
    this.m_CreateMovieToolBarButton.Style = ToolBarButtonStyle.DropDownButton;
    this.m_imageListToolBarButtons.ImageStream = (ImageListStreamer) componentResourceManager.GetObject("m_imageListToolBarButtons.ImageStream");
    this.m_imageListToolBarButtons.TransparentColor = Color.White;
    this.m_imageListToolBarButtons.Images.SetKeyName(0, "");
    this.m_imageListToolBarButtons.Images.SetKeyName(1, "");
    this.m_imageListToolBarButtons.Images.SetKeyName(2, "");
    this.m_imageListToolBarButtons.Images.SetKeyName(3, "");
    this.m_imageListToolBarButtons.Images.SetKeyName(4, "PresentationModeBlueWhite.ico");
    this.m_imageListToolBarButtons.Images.SetKeyName(5, "");
    this.m_imageListToolBarButtons.Images.SetKeyName(6, "settings.ico");
    componentResourceManager.ApplyResources((object) this.m_buttonCancel, "m_buttonCancel");
    this.m_buttonCancel.DialogResult = DialogResult.Cancel;
    this.m_buttonCancel.Name = "m_buttonCancel";
    this.m_buttonCancel.Click += new EventHandler(this.m_buttonCancel_Click);
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).CancelButton = (IButtonControl) this.m_buttonCancel;
    ((Control) this).Controls.Add((Control) this.m_splitContainerMain);
    ((Control) this).Controls.Add((Control) this.m_buttonCancel);
    ((Control) this).Controls.Add((Control) this.m_toolBarCommands);
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiMovMovieManagerForm);
    ((Form) this).Closing += new CancelEventHandler(this.CUiMovMovieManagerForm_Closing);
    ((Form) this).Load += new EventHandler(this.CUiMovMovieManagerForm_Load);
    this.m_splitContainerMain.Panel1.ResumeLayout(false);
    this.m_splitContainerMain.Panel2.ResumeLayout(false);
    this.m_splitContainerMain.EndInit();
    this.m_splitContainerMain.ResumeLayout(false);
    ((ISupportInitialize) this.m_processTreeFlexGrid).EndInit();
    this.m_splitContainerPreview.Panel1.ResumeLayout(false);
    this.m_splitContainerPreview.Panel2.ResumeLayout(false);
    this.m_splitContainerPreview.EndInit();
    this.m_splitContainerPreview.ResumeLayout(false);
    this.m_aviFilesGroupBox.ResumeLayout(false);
    ((ISupportInitialize) this.m_aviFilesFlexGrid).EndInit();
    ((Control) this).ResumeLayout(false);
  }

  [DllImport("user32.dll")]
  private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

  [DllImport("user32.dll")]
  private static extern int EnableMenuItem(IntPtr hMenu, int wIDEnableItem, int wEnable);

  private void CUiMovMovieManagerForm_Load(object sender, EventArgs e)
  {
    this.CreateMovieCreationContextMenu();
    this.CreateMakrByLavelContextMenu();
    this.RestoreUiButtonsStates();
    this.m_processTreeFlexGrid.InitializeProcessTreeGrid(this.m_movieManagerApp);
    this.ClearSelections();
    this.EnablePreviewAndRemoveAttachmentButton(false);
    this.LoadSettings();
  }

  private void CUiMovMovieManagerForm_Closing(object sender, CancelEventArgs e)
  {
    this.m_processTreeFlexGrid.StoreMarkedActivityesStates();
    this.StoreUiButtonsStates();
    this.UnRegisterFromDocumentEvents();
  }

  private void m_processTreeFlexGrid_SelChange(object sender, EventArgs e)
  {
    if (this.m_processTreeFlexGrid.SelectedRowData.Count > 0)
    {
      this.UpdateAviFilesFlexGrid();
    }
    else
    {
      this.m_aviFilesFlexGrid.ClearAVIFIlesData();
      this.m_cUiMovieManagerControl.DisposeAviFile();
      this.EnablePreviewAndRemoveAttachmentButton(false);
    }
  }

  private void m_aviFilesFlexGrid_BeforeSelChange(object sender, RangeEventArgs e)
  {
    TxFileAttachment selectedRowData = this.m_aviFilesFlexGrid.SelectedRowData;
    if (selectedRowData == null)
      return;
    CellRange newRange = e.NewRange;
    int r2 = ((CellRange) ref newRange).r2;
    if (((RowColCollection) ((C1FlexGridBase) this.m_aviFilesFlexGrid).Rows).Count - ((RowColCollection) ((C1FlexGridBase) this.m_aviFilesFlexGrid).Rows).Fixed <= 0 || r2 <= 0)
      return;
    TxFileAttachment key = ((C1FlexGridBase) this.m_aviFilesFlexGrid).Rows[r2].Node.Key as TxFileAttachment;
    if (!(selectedRowData.FullPathInFileSystem == key.FullPathInFileSystem))
      return;
    e.Cancel = true;
  }

  private void m_aviFilesFlexGrid_SelChange(object sender, EventArgs e)
  {
    bool shouldEnable = false;
    if (this.m_processTreeFlexGrid.SelectedRowData.Count > 0)
    {
      CApMovMovieManagerNodeData selectedNodeData = this.m_processTreeFlexGrid.SelectedRowData[0] as CApMovMovieManagerNodeData;
      TxFileAttachment selectedRowData = this.m_aviFilesFlexGrid.SelectedRowData;
      if (selectedNodeData != null && selectedRowData != null)
      {
        shouldEnable = true;
        this.InitializePreviewFileGrid(selectedNodeData, selectedRowData);
      }
      else
      {
        this.m_aviFilesFlexGrid.ClearAVIFIlesSelection();
        this.m_cUiMovieManagerControl.DisposeAviFile();
      }
    }
    this.EnablePreviewAndRemoveAttachmentButton(shouldEnable);
  }

  private void m_processTreeFlexGrid_MouseDown(object sender, MouseEventArgs e)
  {
    if (e.Button != MouseButtons.Right)
      return;
    HitTestInfo hitTestInfo = ((C1FlexGridBase) this.m_processTreeFlexGrid).HitTest(e.X, e.Y);
    if (((HitTestInfo) ref hitTestInfo).Row < ((RowColCollection) ((C1FlexGridBase) this.m_processTreeFlexGrid).Rows).Fixed || ((HitTestInfo) ref hitTestInfo).Row >= ((RowColCollection) ((C1FlexGridBase) this.m_processTreeFlexGrid).Rows).Count)
      return;
    Row row = ((C1FlexGridBase) this.m_processTreeFlexGrid).Rows[((HitTestInfo) ref hitTestInfo).Row];
    if (((RowCol) row).Selected)
      return;
    ((C1FlexGridBase) this.m_processTreeFlexGrid).SelChange -= new EventHandler(this.m_processTreeFlexGrid_SelChange);
    ((C1FlexGridBase) this.m_processTreeFlexGrid).Row = -1;
    foreach (RowCol rowCol in (IEnumerable) ((C1FlexGridBase) this.m_processTreeFlexGrid).Rows.Selected)
      rowCol.Selected = false;
    ((C1FlexGridBase) this.m_processTreeFlexGrid).SelChange += new EventHandler(this.m_processTreeFlexGrid_SelChange);
    ((RowCol) row).Selected = true;
  }

  private void UpdateAviFilesFlexGrid()
  {
    CApMovMovieManagerNodeData nodeData = this.m_processTreeFlexGrid.SelectedRowData[0] as CApMovMovieManagerNodeData;
    if (this.ShouldUpdateAviFilesGrid(nodeData))
    {
      this.m_cUiMovieManagerControl.DisposeAviFile();
      this.m_aviFilesFlexGrid.InitializeAviFilesGrid(nodeData);
    }
    if (nodeData.IsNodeHasAVIAttachments)
      return;
    this.EnablePreviewAndRemoveAttachmentButton(false);
  }

  private bool ShouldUpdateAviFilesGrid(CApMovMovieManagerNodeData nodeData)
  {
    bool flag = true;
    if (nodeData.IsNodeHasAVIAttachments)
    {
      OrderedDictionary attachmentsPathAndDate = nodeData.AttachmentsPathAndDate;
      if (attachmentsPathAndDate.Count == ((RowColCollection) ((C1FlexGridBase) this.m_aviFilesFlexGrid).Rows).Count - ((RowColCollection) ((C1FlexGridBase) this.m_aviFilesFlexGrid).Rows).Fixed)
      {
        flag = false;
        foreach (Row row in (IEnumerable) ((C1FlexGridBase) this.m_aviFilesFlexGrid).Rows)
        {
          if (((RowCol) row).Index > 0)
          {
            TxFileAttachment key = row.Node.Key as TxFileAttachment;
            if (!attachmentsPathAndDate.Contains((object) key))
            {
              flag = true;
              break;
            }
          }
        }
      }
    }
    return flag;
  }

  private void RegisterToDocumentEvents()
  {
    TxApplication.ActiveDocument.Unloading += new TxDocument_UnloadingEventHandler(this.doc_Unloading);
  }

  private void UnRegisterFromDocumentEvents()
  {
    TxApplication.ActiveDocument.Unloading -= new TxDocument_UnloadingEventHandler(this.doc_Unloading);
  }

  private void doc_Unloading(object sender, TxDocument_UnloadingEventArgs args)
  {
    ((Form) this).Close();
  }

  private void EnablePreviewAndRemoveAttachmentButton(bool shouldEnable)
  {
    this.m_removeButton.Enabled = shouldEnable;
    this.m_buttonPreviewMovie.Enabled = shouldEnable;
  }

  private void m_removeButton_Click(object sender, EventArgs e)
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    int rowSel = ((C1FlexGridBase) this.m_aviFilesFlexGrid).RowSel;
    if (this.m_aviFilesFlexGrid.SelectedRowData != null && this.m_processTreeFlexGrid.SelectedRowData.Count > 0)
    {
      RowCollection selected = ((C1FlexGridBase) this.m_aviFilesFlexGrid).Rows.Selected;
      if (this.m_processTreeFlexGrid.SelectedRowData[0] is CApMovMovieManagerNodeData nodeData)
      {
        if (DialogResult.Yes == this.ShowConformationMessageforRemove())
        {
          foreach (Row row in (IEnumerable) selected)
          {
            if (row.Node.Key is TxFileAttachment key && nodeData.CanRemoveAttachment(key))
            {
              nodeData.RemoveAttachment(key);
            }
            else
            {
              int num = (int) MessageBox.Show(StringTable.MOVIE_MANAGER_MESSAGE_CANNOT_REMOVE_ATTACHMENT);
            }
          }
          if (!nodeData.IsNodeHasAVIAttachments)
            this.EnablePreviewAndRemoveAttachmentButton(false);
          this.m_cUiMovieManagerControl.DisposeAviFile();
          this.m_aviFilesFlexGrid.InitializeAviFilesGrid(nodeData);
          this.m_processTreeFlexGrid.ReloadAllProcessTreeNodes(((RowCol) ((C1FlexGridBase) this.m_processTreeFlexGrid).Rows.Selected[0]).Index);
        }
        else
          ((Control) this.m_aviFilesFlexGrid).Select();
      }
    }
    Cursor.Current = current;
  }

  private DialogResult ShowConformationMessageforRemove()
  {
    ResourceManager resourceManager = this.GetResourceManager();
    return TxMessageBox.Show(resourceManager.GetString("MOVIE_MANAGER_ASK_USER_TO_ACCEPT_REMOVE"), resourceManager.GetString("MOVIE_MANAGER_COMMAND_NAME"), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  }

  private void m_buttonPreviewMovie_Click(object sender, EventArgs e)
  {
    if (this.m_aviFilesFlexGrid.SelectedRowData == null || this.m_processTreeFlexGrid.SelectedRowData.Count <= 0)
      return;
    RowCollection selected = ((C1FlexGridBase) this.m_aviFilesFlexGrid).Rows.Selected;
    if (((RowColCollection) selected).Count <= 0)
      return;
    TxFileAttachment key = selected[0].Node.Key as TxFileAttachment;
    if (!(this.m_processTreeFlexGrid.SelectedRowData[0] is CApMovMovieManagerNodeData movieManagerNodeData) || key == null)
      return;
    string path = movieManagerNodeData.NodeObject.DownloadFileAttachment(key);
    if (File.Exists(path))
    {
      try
      {
        new Process()
        {
          StartInfo = {
            FileName = path,
            Verb = "Open",
            CreateNoWindow = true
          }
        }.Start();
      }
      catch (Win32Exception ex)
      {
        ResourceManager resourceManager = this.GetResourceManager();
        string str = resourceManager.GetString("MOVIE_MANAGER_COMMAND_NAME");
        if (ex.NativeErrorCode == 2)
        {
          int num1 = (int) TxMessageBox.Show(resourceManager.GetString("MOVIE_MANAGER_MESSAGE_CAN_LOCATE_FILE"), str, MessageBoxButtons.OK, MessageBoxIcon.Hand);
        }
        else if (ex.NativeErrorCode == 5)
        {
          int num2 = (int) TxMessageBox.Show(resourceManager.GetString("MOVIE_MANAGER_MESSAGE_DONT_HAVE_PERMISSIONS"), str, MessageBoxButtons.OK, MessageBoxIcon.Hand);
        }
        else
        {
          int num3 = (int) TxMessageBox.Show(resourceManager.GetString("MOVIE_MANAGER_MESSAGE_CANT_OPEN_FILE"), str, MessageBoxButtons.OK, MessageBoxIcon.Hand);
        }
      }
    }
    else
    {
      ResourceManager resourceManager = this.GetResourceManager();
      string str = resourceManager.GetString("MOVIE_MANAGER_COMMAND_NAME");
      int num = (int) TxMessageBox.Show(resourceManager.GetString("MOVIE_MANAGER_MESSAGE_CAN_LOCATE_FILE"), str, MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
  }

  private void m_buttonCancel_Click(object sender, EventArgs e) => ((Form) this).Close();

  private void InitializePreviewFileGrid(
    CApMovMovieManagerNodeData selectedNodeData,
    TxFileAttachment selectedAttribute)
  {
    this.m_cannotPlayLabel.Visible = false;
    if (!selectedNodeData.NodeObject.DoesFileAttachmentExist(selectedAttribute.FullPathInFileSystem))
      return;
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    try
    {
      if (this.m_cUiMovieManagerControl.CreateMovie(selectedNodeData.NodeObject.DownloadFileAttachment(selectedAttribute)))
        return;
      this.m_cannotPlayLabel.Text = string.Format(StringTable.MOVIE_MANAGER_FAILED_TO_PREVIEW, (object) selectedAttribute.Name);
      this.m_cannotPlayLabel.Visible = true;
    }
    finally
    {
      Cursor.Current = current;
    }
  }

  private void ClearSelections()
  {
    this.m_processTreeFlexGrid.ClearProcessTreeSelection();
    this.m_aviFilesFlexGrid.ClearAVIFIlesSelection();
    this.m_cUiMovieManagerControl.DisposeAviFile();
  }

  private void UpdateProcessTreeGrid()
  {
    this.m_processTreeFlexGrid.FrozeProcessTree(true);
    this.m_processTreeFlexGrid.ReloadAllProcessTreeNodes();
    if (this.m_processTreeFlexGrid.SelectedRowData.Count > 0)
      this.UpdateAviFilesFlexGrid();
    this.m_processTreeFlexGrid.FrozeProcessTree(false);
  }

  private ResourceManager GetResourceManager()
  {
    return new ResourceManager("DnProcessSimulateCommands.StringTable", ((object) this).GetType().Assembly);
  }

  private void CreateMakrByLavelContextMenu()
  {
    ContextMenu contextMenu = new ContextMenu();
    StringCollection stringCollection = new StringCollection();
    string str = this.GetResourceManager().GetString("MOVIE_MANAGER_MARKBYLAVEL_LEVEL_ITEM");
    stringCollection.Add(str + " 1");
    stringCollection.Add(str + " 2");
    stringCollection.Add(str + " 3");
    stringCollection.Add(str + " 4");
    stringCollection.Add(str + " 5");
    foreach (string text in stringCollection)
    {
      MenuItem menuItem = new MenuItem(text);
      menuItem.Click += new EventHandler(this.levelItem_Click);
      menuItem.Checked = false;
      contextMenu.MenuItems.Add(menuItem);
    }
    this.m_markByLavelToolBarButton.DropDownMenu = (Menu) contextMenu;
  }

  private void levelItem_Click(object sender, EventArgs e)
  {
    if (sender is MenuItem menuItem)
    {
      bool flag = !menuItem.Checked;
      this.ClearAllMenuItems((ContextMenu) menuItem.Parent);
      menuItem.Checked = flag;
    }
    this.MakrByLevel(menuItem.Index);
  }

  private void MakrByLevel(int levelIndex)
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    this.m_processTreeFlexGrid.MarkByLevel(levelIndex);
    this.m_processTreeFlexGrid.ExpandTreeToCurrentLavel(levelIndex);
    Cursor.Current = current;
  }

  private int GetSelectedMenuItim(Menu.MenuItemCollection menuItems)
  {
    int selectedMenuItim = -1;
    foreach (MenuItem menuItem in menuItems)
    {
      if (menuItem.Checked)
      {
        selectedMenuItim = menuItem.Index;
        break;
      }
    }
    return selectedMenuItim;
  }

  private void CreateMovieCreationContextMenu()
  {
    ContextMenu contextMenu = new ContextMenu();
    StringCollection stringCollection = new StringCollection();
    ResourceManager resourceManager = this.GetResourceManager();
    stringCollection.Add(resourceManager.GetString("MOVIE_MANAGER_MENU_ITEM_ADDADDITIONAL"));
    stringCollection.Add(resourceManager.GetString("MOVIE_MANAGER_MENU_ITEM_CREATEMISSING"));
    stringCollection.Add(resourceManager.GetString("MOVIE_MANAGER_MENU_ITEM_OVERWRITEALL"));
    foreach (string text in stringCollection)
    {
      MenuItem menuItem = new MenuItem(text);
      menuItem.Click += new EventHandler(this.movieItem_Click);
      menuItem.Checked = false;
      contextMenu.MenuItems.Add(menuItem);
    }
    this.m_CreateMovieToolBarButton.DropDownMenu = (Menu) contextMenu;
  }

  private void movieItem_Click(object sender, EventArgs e)
  {
    MenuItem menuItem = sender as MenuItem;
    if (menuItem == null)
      return;
    bool flag = !menuItem.Checked;
    ContextMenu parent = (ContextMenu) menuItem.Parent;
    this.ClearAllMenuItems(parent);
    menuItem.Checked = flag;
    if (flag)
      return;
    parent.MenuItems[0].Checked = true;
  }

  private void ClearAllMenuItems(ContextMenu parent)
  {
    foreach (MenuItem menuItem in parent.MenuItems)
      menuItem.Checked = false;
  }

  private void m_toolBarCommands_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    switch (((ToolBar) this.m_toolBarCommands).Buttons.IndexOf(e.Button))
    {
      case 0:
        this.m_processTreeFlexGrid.MarkAll();
        break;
      case 1:
        int selectedMenuItim = this.GetSelectedMenuItim(this.m_markByLavelToolBarButton.DropDownMenu.MenuItems);
        if (selectedMenuItim >= 0)
        {
          this.MakrByLevel(selectedMenuItim);
          break;
        }
        break;
      case 2:
        this.m_processTreeFlexGrid.MarkLinesWithoutMovies();
        break;
      case 3:
        this.m_processTreeFlexGrid.ClearAll();
        break;
      case 5:
        this.OpenSettingDialog();
        break;
      case 7:
        this.GenerateAviFiles(this.GetSelectedMenuItim(this.m_CreateMovieToolBarButton.DropDownMenu.MenuItems));
        break;
    }
    Cursor.Current = current;
  }

  private void GenerateAviFiles(int selectedmodeIndex)
  {
    string selectedModeAsString = "";
    if (this.m_processTreeFlexGrid.GetAllMarkedData().Count > 0)
    {
      if (this.m_processTreeFlexGrid.GetAllData().Count <= 0)
        return;
      ResourceManager resourceManager = this.GetResourceManager();
      CApMovMovieManagerApp.AVIGenerationMode generationMode = CApMovMovieManagerApp.AVIGenerationMode.AddAditionalMovies;
      if (selectedmodeIndex < 0)
        return;
      switch (selectedmodeIndex)
      {
        case 0:
          generationMode = CApMovMovieManagerApp.AVIGenerationMode.AddAditionalMovies;
          selectedModeAsString = resourceManager.GetString("MOVIE_MANAGER_MENU_ITEM_ADDADDITIONAL");
          break;
        case 1:
          generationMode = CApMovMovieManagerApp.AVIGenerationMode.CreateMissingMovies;
          selectedModeAsString = resourceManager.GetString("MOVIE_MANAGER_MENU_ITEM_CREATEMISSING");
          break;
        case 2:
          generationMode = CApMovMovieManagerApp.AVIGenerationMode.OverrideAllMovies;
          selectedModeAsString = resourceManager.GetString("MOVIE_MANAGER_MENU_ITEM_OVERWRITEALL");
          break;
      }
      if (DialogResult.OK != this.AskUserToAcceptGenerationMode(selectedModeAsString))
        return;
      this.m_buttonCancel.Enabled = false;
      // ISSUE: explicit non-virtual call
      CUiMovMovieManagerForm.EnableMenuItem(CUiMovMovieManagerForm.GetSystemMenu(__nonvirtual (((Control) this).Handle), false), 61536, 1);
      Cursor current = Cursor.Current;
      Cursor.Current = Cursors.WaitCursor;
      this.StartGenerationProcess(generationMode, this.m_processTreeFlexGrid.GetAllData());
      this.m_buttonCancel.Enabled = true;
      // ISSUE: explicit non-virtual call
      CUiMovMovieManagerForm.EnableMenuItem(CUiMovMovieManagerForm.GetSystemMenu(__nonvirtual (((Control) this).Handle), false), 61536, 0);
      this.UpdateProcessTreeGrid();
      Cursor.Current = current;
    }
    else
      this.ShowNotSelectedOperationsMessage();
  }

  private void StartGenerationProcess(
    CApMovMovieManagerApp.AVIGenerationMode generationMode,
    ArrayList selectedObjects)
  {
    // ISSUE: explicit non-virtual call
    int num = (int) new CUiMovAviGeneratorForm(__nonvirtual (((Control) this).Bounds), this.m_movieManagerApp.Recorder).ShowDialog((TxForm) this, generationMode, selectedObjects);
  }

  private DialogResult AskUserToAcceptGenerationMode(string selectedModeAsString)
  {
    ResourceManager resourceManager = this.GetResourceManager();
    string format = resourceManager.GetString("MOVIE_MANAGER_ASK_USER_TO_ACCEPT_GENERATION");
    string str = resourceManager.GetString("MOVIE_MANAGER_COMMAND_NAME");
    return TxMessageBox.Show($"{string.Format(format, (object) selectedModeAsString)}\n\n{resourceManager.GetString("MOVIE_MANAGER_ASK_USER_TO_ACCEPT_GENERATION_INFORMATION")}", str, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  }

  private void ShowNotSelectedOperationsMessage()
  {
    ResourceManager resourceManager = this.GetResourceManager();
    int num = (int) TxMessageBox.Show(resourceManager.GetString("MOVIE_MANAGER_OPERATIONS_ARE_NOT_SELECTED"), resourceManager.GetString("MOVIE_MANAGER_COMMAND_NAME"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  }

  private void StoreUiButtonsStates()
  {
    this.StoreMarkByLevel();
    this.StoreCreateMoviesMode();
  }

  private void RestoreUiButtonsStates()
  {
    this.RestoreMarkByLevel();
    this.RestoreCreateMoviesMode();
  }

  private void StoreMarkByLevel()
  {
    int selectedMenuItim = this.GetSelectedMenuItim(this.m_markByLavelToolBarButton.DropDownMenu.MenuItems);
    TxFormSettings.StoreFormValue((Form) this, this.GetResourceManager().GetString("MOVIE_MANAGER_MENU_COLLECTION_NAME"), this.GetResourceManager().GetString("MOVIE_MANAGER_MENU_MARK_BY_LAVEL"), selectedMenuItim.ToString());
  }

  private void StoreCreateMoviesMode()
  {
    int selectedMenuItim = this.GetSelectedMenuItim(this.m_CreateMovieToolBarButton.DropDownMenu.MenuItems);
    TxFormSettings.StoreFormValue((Form) this, this.GetResourceManager().GetString("MOVIE_MANAGER_MENU_COLLECTION_NAME"), this.GetResourceManager().GetString("MOVIE_MANAGER_MENU_CREATE_MOVIE_FOR_ALL_MARKED"), selectedMenuItim.ToString());
  }

  private void RestoreMarkByLevel()
  {
    object s;
    TxFormSettings.RestoreFormValue((Form) this, this.GetResourceManager().GetString("MOVIE_MANAGER_MENU_COLLECTION_NAME"), this.GetResourceManager().GetString("MOVIE_MANAGER_MENU_MARK_BY_LAVEL"), ref s);
    if (s == null)
      return;
    int index = int.Parse(s as string);
    if (index < 0)
      return;
    this.m_markByLavelToolBarButton.DropDownMenu.MenuItems[index].Checked = true;
  }

  private void RestoreCreateMoviesMode()
  {
    object s;
    TxFormSettings.RestoreFormValue((Form) this, this.GetResourceManager().GetString("MOVIE_MANAGER_MENU_COLLECTION_NAME"), this.GetResourceManager().GetString("MOVIE_MANAGER_MENU_CREATE_MOVIE_FOR_ALL_MARKED"), ref s);
    int index = 0;
    if (s != null)
    {
      index = int.Parse(s as string);
      if (index < 0)
        index = 0;
    }
    this.m_CreateMovieToolBarButton.DropDownMenu.MenuItems[index].Checked = true;
  }

  private void LoadSettings()
  {
    CApMRCRecorderSettings recorderSettings = new CApMRCRecorderSettings();
    object obj;
    TxFormSettings.RestoreFormValue((Form) this, "Movie Manager Settings", ref obj);
    if (obj != null)
      recorderSettings = CApMRCRecorderUtilities.DeserializeSettings(obj.ToString());
    recorderSettings.Validate();
    this.m_movieManagerApp.Recorder = new CApMovMovieRecorder();
    this.m_movieManagerApp.Recorder.Settings = recorderSettings;
  }

  private void SaveSettings()
  {
    TxFormSettings.StoreFormValue((Form) this, "Movie Manager Settings", (object) CApMRCRecorderUtilities.SerializeSettings(this.m_movieManagerApp.Recorder.Settings));
  }

  private void OpenSettingDialog()
  {
    CApMRCRecorderSettings recorderSettings = new CApMRCRecorderSettings(this.m_movieManagerApp.Recorder.Settings);
    bool? nullable = new CUiMRCRecorderSettingsWindow(recorderSettings, SettingsView.MovieManager).ShowDialog(true);
    if (!nullable.HasValue || !nullable.Value)
      return;
    this.m_movieManagerApp.Recorder.Settings = recorderSettings;
    this.SaveSettings();
  }
}
